package com.ict.txmsv2.services;

import com.ict.txmsv2.utils.OSSutils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author linzzz
 * @desc ...
 * @date 2020-12-17
 */
@Service
public class UploadService {
    @Autowired
    UserService userService;

    public int uploadAvatar(Integer userId, MultipartFile file) {
        String uri = "";
        try {
            uri = OSSutils.uploadAvatar(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return userService.updateAvatar(userId,uri);
    }

    /**
     * 上传图片并返回图片的url
     * @param file
     * @return
     */
    public String uploadHonorary(MultipartFile file) {
        String url = "";
        try {
            url = OSSutils.uploadAvatar(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return url;
    }
}
